package main

import (
	"fmt"
	"os"
)

func main() {
	var (
		name   string
		age    string
		gender string
	)
	// 需要自己先手动创建students.txt
	//f, err := os.OpenFile("students.txt", os.O_WRONLY, 6)
	// 直接创建文件
	f, err := os.Create("students.txt")
	defer f.Close()
	if err != nil {
		fmt.Println("write error:", err)
		return
	}
	f.WriteString("姓名，性别，年龄\n")
	for i := 1; i < 4; i++ {
		fmt.Printf("请输入第%d个学生的姓名：", i)
		fmt.Scan(&name)
		fmt.Printf("请输入第%d个学生的性别：", i)
		fmt.Scan(&gender)
		fmt.Printf("请输入第%d个学生的年龄：", i)
		fmt.Scan(&age)
		f.WriteString(name + "," + gender + "," + age + "\n")
	}
}
